'use strict';
import {  Body, Controller, Inject, Post, Provide} from '@midwayjs/decorator';
import UserService from "../service/userService";
// import {plugin} from 'plugin';
// import {Application, Context} from 'egg';

// import * as randomBytes from 'randombytes'

@Provide()
@Controller('/user')
export class UserController {
  @Inject()
  userService: UserService;

  @Post('/list')
  async userList() {
    const userList = await this.userService.getList()
    return userList;
  }

  @Post('/save')
  async userSave(@Body('userData') data: object) {
    const rs = await this.userService.save(data).catch(err => {
      return {
        success: false,
        msg:'保存失败'
      }
    })
    return rs
  }

  @Post('/delete')
  async userDelete(@Body('id') id:string){
    const rs=await this.userService.delete(id).catch(err=>{
      console.log('删除失败：',err);
      return {
        success: false,
        msg:'删除失败！'
      }
    })
    return rs
  }

}

